<template>
	<view class="box">
		<!-- #ifdef H5 || MP-WEIXIN -->
		<view class="">
			<u-navbar title="管理员列表" :fixed="true" :placeholder="true" :safeAreaInsetTop="true" :autoBack="false"
				leftIconColor="#666" titleStyle="color:#333" bgColor="transparent" @leftClick="leftClick"></u-navbar>
			<image class="indexbg"
				src="https://images.fudiemall.com/storage/default/20250411/BG77ff634c5c493fbb0cb752c7b44d86c703900c11.png"
				mode="aspectFill"></image>
		</view>
		<!-- #endif -->

		<!-- #ifdef MP-ALIPAY -->
		<NavTitle title="管理员列表"
			bgimg='https://images.fudiemall.com/storage/default/20250411/BG77ff634c5c493fbb0cb752c7b44d86c703900c11.png'
			:backgroundColor='backgroundColor'></NavTitle>
		<!-- #endif -->
		<view class="main">
			<u-checkbox-group iconPlacement="right" placement="column" @change="checkboxChangeAll">
				<view class="item" v-for="item in merberlist" :key="item.id">
					<image :src="item.user.avatar" mode="aspectFill"></image>
					<text>{{item.user.nickname}}</text>
					<view class="tag" v-if="item.is_admin==1">
						群主
					</view>
					<view class="tag" v-if="item.is_admin==2">
						管理员
					</view>
					<u-checkbox v-if="isshow" shape='circle' class="checkitem" size='15' :checked='false'
						activeColor='#FFC300' :name="item.user_id.toString()"></u-checkbox>
				</view>
			</u-checkbox-group>
			<!-- <checkbox-group @change="checkboxChangeAll">
				<view class="item" v-for="item in merberlist" :key="item.id">
					<image :src="item.user.avatar" mode="aspectFill"></image>
					<text>{{item.user.nickname}}</text>
					<view class="tag" v-if="item.is_admin==1">
						群主
					</view>
					<view class="tag" v-if="item.is_admin==2">
						管理员
					</view>
					<checkbox v-if="isshow" borderColor="#333" activeBorderColor="#FFC300" class="checkitem"
						activeBackgroundColor="#FFC300" backgroundColor="#f2f2f2" :checked="false"
						:value="item.user_id.toString()"></checkbox>
				</view>
			</checkbox-group> -->
		</view>
		<noDatas :xxxList="merberlist" :showMore="false"></noDatas>

		<view class="empty3">

		</view>
		<view class="empty3">

		</view>

		<view class="btn" @click="right">
			{{righttxt}}
		</view>

		<view style="width: 750rpx;height: 88rpx;">

		</view>
	</view>
</template>

<script>
	import {
		groupDetails,
		adminList,
		setAdministrator
	} from "../../api/hx.js"
	import {
		myuser
	} from "../../api/user.js"
	export default {
		data() {
			return {
				selectedIds: [],
				isshow: false,
				righttxt: "管理成员",
				word: "",
				merberlist: [],
				groupid: "",
				tit: "",
				groupinfo: "",
				is_admin: "",
				user: {},
				backgroundColor: ""
			}
		},
		onLoad(option) {
			this.groupid = option.id
			this.getlist()
			this.groupdetail()
		},
		// 页面滚动
		onPageScroll: function(e) {
			const scrollTop = e.scrollTop; // 获取页面滚动位置
			// 根据滚动位置修改状态栏样式
			if (scrollTop > 20) {
				this.backgroundColor = '#ffffff';
			} else {
				this.backgroundColor = '';
			}
			// console.log("滚动距离为：" + e.scrollTop);
		},
		onShow() {
			this.groupdetail()
			this.getuser()
		},
		methods: {
			set() {
				setAdministrator({
					hx_group_id: this.groupid,
					is_admin: "0",
					admin_member_id: this.selectedIds.join(",")
				}).then(res => {
					if (res.code == 1) {
						this.getlist()
						this.selectedIds = []
						this.righttxt = "管理成员"
						this.isshow = false
					}
					uni.$u.toast(res.msg)
					// console.log()
				})
			},
			getuser() {
				myuser().then(res => {
					this.user = res.data
				})
			},
			gomore(item) {
				if (this.is_admin != 0 && this.user.id != item.member_id) {

					uni.setStorageSync("groupitem", item)
					uni.navigateTo({
						url: "/pagesMy/chat/more?id=" + this.groupid
					})

				}
			},
			leftClick() {
				//获取页面栈的长度
				const canNavBack = getCurrentPages()
				console.log(canNavBack.length);
				// 判断是否刷新了浏览器，刷新了浏览器，页面栈只有当前一个
				if (canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: '/pages/index/cloudCatIndex'
					})
				}
			},
			sub() {
				this.page = 1,
					this.getlist()
			},
			groupdetail() {
				groupDetails({
					hx_group_id: this.groupid
				}).then(res => {
					if (res.code == 1) {
						this.groupinfo = res.data
						this.is_admin = res.data.group_user_one.is_admin
						this.tit = `${this.groupinfo.name}(${this.groupinfo.member_number}人)`
						// console.log("群详情", res)
					} else {
						uni.$u.toast(res.msg)
					}

				})
			},
			getlist() {
				adminList({
					hx_group_id: this.groupid,

				}).then(res => {
					if (res.code == 1) {
						this.merberlist = res.data

					}
				})
			},
			leftClick() {
				//获取页面栈的长度
				const canNavBack = getCurrentPages()
				console.log(canNavBack.length);
				// 判断是否刷新了浏览器，刷新了浏览器，页面栈只有当前一个
				if (canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: '/pages/index/cloudCatIndex'
					})
				}
			},
			right() {
				this.isshow = true
				this.righttxt = "删除管理员"
				if (this.selectedIds.length != 0) {
					this.set()

					this.righttxt = "管理成员"

				}
			},
			checkboxChangeAll(e) {
				this.selectedIds = e;
				console.log(this.selectedIds)
			},
		},

	}
</script>
<style>
	page {
		background-color: #f7f7f7;
	}
</style>
<style lang="scss">
	.box {
		width: 750rpx;

	}

	.btn {
		width: 696rpx;
		height: 80rpx;
		background: linear-gradient(270deg, #FA2222 2%, #FFC400 98%);
		border-radius: 190rpx 190rpx 190rpx 190rpx;
		font-weight: 500;
		font-size: 36rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 80rpx;
		position: fixed;
		bottom: 50rpx;
		left: 50%;
		transform: translateX(-50%);
	}

	/deep/.u-navbar__content {
		background: transparent;
	}

	.indexbg {
		position: absolute;
		top: 0;
		left: 0;
		width: 750rpx;
		height: 460rpx;

	}

	/deep/ .u-navbar__content__right__text {
		color: #FF1616;
	}

	.wrap_top {
		width: 750rpx;
	}

	.search {
		width: 690rpx;
		height: 72rpx;
		background: #E0DDDA;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		margin: 0 auto;
		position: relative;

		>image {
			width: 32rpx;
			height: 30rpx;
			position: absolute;
			top: 22rpx;
			left: 34rpx;

		}

		>input {
			width: 620rpx;
			padding-left: 70rpx;
			height: 72rpx;
			font-weight: 400;
			font-size: 28rpx;
			color: rgba(255, 255, 255, 0.8);
		}
	}

	.main {
		width: 750rpx;
		position: relative;
		z-index: 15;
	}

	.item {
		width: 690rpx;
		margin: 0 auto;
		margin-top: 24rpx;
		display: flex;
		align-items: center;
		position: relative;

		>image {
			width: 84rpx;
			height: 84rpx;
			border-radius: 50%;
		}

		>text {
			font-weight: 400;
			font-size: 30rpx;
			color: #333;
			margin-left: 15rpx;
			max-width: 300rpx;
			white-space: nowrap;
			/* 防止文本换行 */
			overflow: hidden;
			/* 隐藏溢出的文本 */
			text-overflow: ellipsis;
			/* 当文本溢出时显示省略号 */
		}

		.tag {
			padding: 5rpx 10rpx 5rpx 10rpx;
			background: #FFC300;
			border-radius: 4rpx 4rpx 4rpx 4rpx;
			opacity: 0.5;
			font-size: 20rpx;
			color: #fff;
			text-align: center;
			margin-left: 20rpx;
		}

		/deep/.uni-checkbox-input {
			width: 30rpx;
			height: 30rpx;
			position: absolute;
			right: 40rpx;
			border-radius: 50%;
		}

		/* #ifdef MP-WEIXIN */

		.checkitem {
			width: 30rpx;
			height: 30rpx;
			position: absolute;
			right: 40rpx;
			border-radius: 50%;

		}

		/* #endif */
		/deep/.u-checkbox {
			width: 30rpx;
			height: 30rpx;
			position: absolute;
			right: 40rpx;
			border-radius: 50%;
		}
	}
</style>